package com.lsd.game.lastrun.model;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.lsd.game.lastrun.Constants;

/*
 * This class defines the properties of the most BASIC and GENERIC object. More specific
 * objects should inherit from this class and contain more defined properties and methods.
 */
public class AbstractObject {
	
	/* Class members */
	
	protected Vector2 position; // Where is the object?
	protected Texture texture; // How does the object look like?
	protected Rectangle debugRect; // Used for debug rendering
	protected float size; // How big is our objects in units?
	
	/* Class methods */
	
	//////////////////
	// CONSTRUCTORS //
	//////////////////
	
	// Makes the object and places it at (0,0)
	public AbstractObject() {
		position = new Vector2();
		position.x = Constants.DEFAULT_OBJECT_XPOS;
		position.y = Constants.DEFAULT_OBJECT_YPOS;
		
		size = Constants.DEFAULT_OBJECT_SIZE;
		
		debugRect = new Rectangle();
		debugRect.width = Constants.DEFAULT_OBJECT_DEBUG_WIDTH;
		debugRect.height = Constants.DEFAULT_OBJECT_DEBUG_HEIGHT;
	}
	
	public AbstractObject(Vector2 pos) {
		position = pos;
		
		size = Constants.DEFAULT_OBJECT_SIZE;
		
		debugRect = new Rectangle();
		debugRect.width = Constants.DEFAULT_OBJECT_DEBUG_WIDTH;
		debugRect.height = Constants.DEFAULT_OBJECT_DEBUG_HEIGHT;
	}
	
	public AbstractObject(Vector2 pos, float objSize) {
		position = pos;
		size = objSize;
		
		debugRect = new Rectangle();
		debugRect.width = objSize;
		debugRect.height = objSize;
	}
	
	public AbstractObject(Vector2 pos, float objSize, String textureName) {
		position = pos;
		size = objSize;
		setTexture(textureName);
		
		debugRect = new Rectangle();
		debugRect.width = objSize;
		debugRect.height = objSize;
	}
	
	/////////////////
	// GET METHODS //
	/////////////////

	public Vector2 getPosition() { return position; }
	public Texture getTexture() { return texture; }
	public Rectangle getDebugRect() { return debugRect; }
	public float getSize() { return size; }
	
	/////////////////
	// SET METHODS //
	/////////////////
	
	public void setPosition(float newX, float newY) {
		position.x = newX;
		position.y = newY;
	}
	
	public void setPosition(Vector2 newPos) {
		position = newPos;
	}
	
	public void setDebugRectBounds(float newWidth, float newHeight) {
		debugRect.width = newWidth;
		debugRect.height = newHeight;
	}
	
	public void setDebugRectBounds(Rectangle newRect) {
		debugRect = newRect;
	}
	
	public void setTexture(String textureName) {
		// If the texture doesn't exist, use the gross default picture
		if (Gdx.files.internal(Constants.DEFAULT_IMG_DIR + textureName + ".png").exists() != false) {
			texture = new Texture(Gdx.files.internal(Constants.DEFAULT_IMG_DIR 
					+ textureName + ".png"));
		}
		else {
			Gdx.app.log(Constants.DEBUG_ERROR, "Object (" + this.getClass().getSimpleName() + ") has no texture!");
			texture = new Texture(Gdx.files.internal(Constants.DEFAULT_OBJET_TEXTURE));
		}
	}
	
	///////////////////
	// UPDATE METHOD //
	///////////////////
	
	public void update(float delta) {
		; // Override this with relevant stuff in a child class
	}
}
